<?php $this->load->view('header');?>

<style>
.layui-form-onswitch{border-color: #1e9fff;background-color: #1e9fff;}
.layui-btn-primary:hover{border-color: #1e9fff;}
</style>

<body class="childrenBody">
    <blockquote class="layui-elem-quote news_search">
		<form class="layui-form" action="" style="display: inline;">
			<div class="layui-inline">
			    <div class="layui-input-inline">
			    	<input type="text" name="keyword" value="" placeholder="搜手机、姓名" class="layui-input search_input">
			    </div>
				
			    <a class="layui-btn layui-btn-normal Sear_btn"><i class="layui-icon">&#xe615;</i>查询</a>
			</div>
		</form>
		<div style="float: right;">
			<div class="layui-inline">
				<a class="layui-btn layui-btn-primary Set_btn"><i class="layui-icon">&#xe716;</i> 设置</a>
				<a class="layui-btn layui-btn-primary add_btn"><i class="layui-icon">&#xe654;</i> 添加会员</a>
			</div>
		</div>
	</blockquote>

	<!-- 视图 -->
	<div class="layui-form news_list">
		<form class="layui-form">
			<table class="layui-table" lay-even="" lay-skin="line">
			    <thead>
				<tr>
					<th>姓名</th>
					<th>电话</th>
					<th>性别</th>
					<th>标签</th>
					<th>操作</th>
				</tr> 
			    </thead>
				<tbody class="goods_content" id="view"></tbody>
			</table>
			<div class="page_box" style="float: right;padding-right: 10px;">
				<div id="listpage"></div>
			</div>
		</form>
	</div>

	<div style="display: none;" id="editForm">
		<form class="layui-form" action="">
			<div class="layui-form-item" style="text-align: center;line-height: 115px;">
				<input type="radio" name="examine" value="1" title="需要" <?php if ($info == 1):?> checked <?php endif;?>>
				<input type="radio" name="examine" value="2" title="不需要"  <?php if ($info == 2):?> checked <?php endif;?>>
			</div>
		</form>
	</div>
	
	<div style="display: none;" id="add_userBox">
		<form class="layui-form" id="member" action="" style="padding:20px 0;">
			<div class="layui-form-item">
				<label class="layui-form-label">验证手机</label>
				<div class="layui-input-inline" style="width:250px;">
					<input type="tel" name="mobile" lay-verify="required|phone" autocomplete="off" class="layui-input" style="width:240px;display: inline-block;">
					<span style="color:red;">*</span>
				</div>
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">昵称</label>
				  <div class="layui-input-inline" style="width:240px;">
					<input type="text" name="nickname"  class="layui-input">
				  </div>
			</div>
			<div class="layui-form-item">
				  <label class="layui-form-label">性别</label>
				  <div class="layui-input-block">
						<input type="radio" name="sex" value="0" title="未知" checked="">
						<input type="radio" name="sex" value="1" title="男">
						<input type="radio" name="sex" value="2" title="女">
				  </div>
				
			</div>
			
			<div class="layui-form-item">
				<label class="layui-form-label">生日</label>
				<div class="layui-input-inline" style="width:240px;">
					<input type="text" name="birthday" class="layui-input">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">地址</label>
				<div class="layui-input-inline" style="width:160px;">
					<input type="text" name="province" class="layui-input" style="display: inline-block;width: 140px;">省
				</div>
				<div class="layui-input-inline" style="width:160px;">
					<input type="text" name="city" class="layui-input" style="display: inline-block;width: 140px;">市
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">详细信息</label>
				<div class="layui-input-block">
					<textarea placeholder="请输入内容" name="info" style="width: 500px;" class="layui-textarea"></textarea>
				</div>
			</div>
		</form>
		
	</div>

	<!-- 模板 -->
	<script id="demo" type="text/html">
	    {{#  layui.each(d.list, function(index, item){ }}
			<tr>
			  <td align="left">
			  	{{#  if(item.headimg){ }}
			  	<img src="{{item.headimg}}" style="width: 30px;border-radius: 100%;height: 30px;">
			  	{{# }else{ }}
				<img src="plugins/layui/images/user_img.png" style="width: 30px;border-radius: 100%;">
			  	{{#  } }} 
			  	&nbsp;&nbsp;{{ item.nickname }}
			  </td>
			  <td>{{ item.mobile }}</td>
			  <td>{{ item.sex }}</td>
			  <td>{{ item.label }}</td>
			  <td>
			    <a class="layui-btn layui-btn-mini" id="viewlog{{ item.id }}" title="详情">
			      <i class="layui-icon">&#xe60a;</i>详情
			    </a>
			    <input type="checkbox" name="disabled" {{#  if(item.disabled != 1){ }} checked="" {{#  } }} lay-skin="switch" lay-filter="disab_switch{{item.id}}" lay-text="允许|禁止">
			  </td>
			</tr>
	    {{#  }); }}

	    {{#  if(d.list.length === 0){ }}
	      暂无数据
	    {{#  } }} 
	</script>

<script type="text/javascript">

var WuClass = function(){
	
}

WuClass.prototype = {
	addMember(){
		
		var data = $('#member').serializeArray();
		var postdata = {};
		for(var i=0;i<data.length;i++){
			postdata[data[i].name] = data[i].value;
		}
		
		$.post('admin.php/UserMember/add',postdata, function(result){
			if(result.result_code==0){
				alert('添加成功');
				location.reload();
			}
			else{
				alert(result.message);
			}

		},'json');
		
		
	}
	
};

var Wu = new WuClass();




	layui.config({
		version: true
	}).use(['jquery','layer', 'laytpl', 'form', 'element', 'laypage'],function(){
		var layer = parent.layer === undefined ? layui.layer : parent.layer,
			laytpl = layui.laytpl,
			form = layui.form,
			element = layui.element,
			laypage = layui.laypage,
			$ = layui.jquery;

			load_list();

			//查询
			$('.Sear_btn').click(function() {
				var keyword = $("input[name='keyword']").val();
				load_list('',keyword);
			});
			

			//设置
			$('.Set_btn').click(function() 
			{
				var index = layui.layer.open({
					title : "会员注册是否需要审核？",
					type : 1,
					btn: ['确 定'],
					area: ['666px', '230px'],
					offset: '70px',
					content : $('#editForm'),
					yes: function(index, layero)
					{
					    var exa = $('input[name="examine"]:checked').val();

					    $.get('admin.php/UserMember/set_examine', {examine: exa}, function(r) 
					    {
					    	layer.msg(r.message, {icon:1});
					    	layer.close(index); //再执行关闭 
							location.reload();

					    },'json');

					} 
				});
				
			});
			

			
			//添加会员
			$('.add_btn').click(function() {
				
				var index = layui.layer.open({
					title : "会员信息",
					type : 1,
					btn: ['确 定'],
					area: ['720px', '550px'],
					offset: '70px',
					content : $('#add_userBox'),
					yes: function(index, layero){
						Wu.addMember();
					} 
				});
				
			});


			function load_list(page,k)
			{
				var p = page ? page : '';
				var k = k ? k : '';

				$.get('admin.php/UserMember/get_list',{page:p,keyword:k}, function(data) 
				{
					var getTpl = demo.innerHTML;
					laytpl(getTpl).render(data, function(html){
					  $('#view').html(html);
					});


					layui.each(data.list, function(index, el) 
					{
						//分页
						laypage.render({
						  elem: 'listpage'
						  ,count: data.count //数据总数，从服务端得到
						  ,theme: '#1E9FFF'
						  ,limit: 20
						  ,curr:p
						  ,jump: function(obj, first){
						    //首次不执行
						    if(!first){
						      load_list(obj.curr,k);
						    }
						  }
						});

						//查看详情
						$('#viewlog'+el.id).click(function() 
						{
							var index = layui.layer.open({
								title : "会员详情",
								type : 2,
								content : "admin.php/UserMember/member_info/"+el.id,
							})

							//改变窗口大小时，重置弹窗的高度，防止超出可视区域
							$(window).resize(function(){
								layui.layer.full(index);
							})
							layui.layer.full(index);
						});

						//审核
						form.on('switch(disab_switch'+el.id+')', function(data)
						{
							var val = !data.elem.checked ? '1' : '0';
							$.get('admin.php/UserMember/set_disabled',{uid:el.id,disabled:val}, function(r) 
							{
								if (r.status == 400) 
								{
									layer.msg(r.message);
									data.elem.checked = false;
								}
								else
								{
									layer.msg(r.message);
								}

								form.render();

							},'json');
						});

						form.render(); //更新全部
					});

				},'json');

			}

	});
	</script>

</body>
</html>